package com.wzy.ssm.match.controller;

import com.wzy.ssm.match.model.MatchList;
import com.wzy.ssm.match.model.MatchListExample;
import com.wzy.ssm.match.service.MatchListService;
import com.wzy.ssm.util.IdUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//添加注解
@Controller
public class MatchListController {

    private MatchListService matchListService;

    //通过构�?�器注入service
    public MatchListController(MatchListService matchListService){
        this.matchListService=matchListService;
    }

    //查询数据
    @GetMapping("/matchList")
    @ResponseBody
    public List<MatchList> selectMatchList(){
        //1 构�?�查询条�?
        //1.1 创建查询条件�?
        MatchListExample example = new MatchListExample();
        //1.2 创建条件构�?�器
        MatchListExample.Criteria criteria = example.createCriteria();
        //1.3 通过criteria设置条件
        //...

        //2 根据条件查询
        List<MatchList> list = matchListService.selectByExample(example);

        return list;
    }
    //添加数据
    @PostMapping("/matchList")
    @ResponseBody
    public MatchList insertUser(@RequestBody MatchList matchList){
        //准备数据
        //自动生成id
        short stute = 0;
        matchList.setMatchId(IdUtil.nextId9());
        matchList.setMatchStute(stute);
        matchListService.insertSelective(matchList);

        return matchList;
    }
    //修改数据
    @PutMapping("/matchList")
    @ResponseBody
    public MatchList updateUser(@RequestBody MatchList matchList){
        //准备数据
        //...

        matchListService.updateByPrimaryKeySelective(matchList);
        //只返回修改的字段数据
        return matchList;
        //或�??,通过主键,从数据库查询完整的数�?,然后返回
        //return matchListService.selectByPrimaryKey(matchList.getMatchListId);

    }
    //删除数据
    @DeleteMapping("/matchList/{id}")
    @ResponseBody
    public String delUser(@PathVariable("id") Integer matchListId){

        matchListService.deleteByPrimaryKey(matchListId);

        //返回状�?�码
        return "200";
    }
}
